package test_error

import "fmt"

type TestError struct {
	code int
	msg  string
}

func (s *TestError) Error() string {
	return fmt.Sprintf("code=%d msg=%s", s.code, s.msg)
}

func runAdd(a, b int) (int, error) {
	if a == 0 || b == 0 {
		return 0, &TestError{code: 1, msg: "参数不能为0"}
	}
	return a + b, nil
}

func Do() {
	fmt.Println("error测试")
	result, err := runAdd(0, 1)
	if err != nil {
		fmt.Println(err.Error())
	} else {
		fmt.Println(result)
	}
}
